﻿using System.Windows.Forms;
using ApplicationGenerator.Lists.BusinessLogic;

namespace GUserInterface.WinForms.Lists
{
    public partial class TypeConfigurationControl : BaseWizardPage
    {
        private readonly string _treeConfigurationType = "Z drzewa modelu";
        private readonly string _hqlConfiguration = "Zapytanie HQL";

        public TypeConfigurationControl()
        {
            InitializeComponent();
            AdditionalInitialize();
        }

        private void AdditionalInitialize()
        {
            cbConfigurationType.Items.Add(_treeConfigurationType);
            cbConfigurationType.Items.Add(_hqlConfiguration);

            cbConfigurationType.SelectedIndex = 0;
        }

        public override void ShowPage(Panel wizardSheet, ListConfiguration listConfiguration)
        {
            if (!wizardSheet.Controls.Contains(this))
            {
                this.Dock = DockStyle.Fill;
                wizardSheet.Controls.Add(this);
            }

            cbConfigurationType.SelectedItem = _hqlConfiguration;
            cbConfigurationType.Enabled = false;

            tbListName.Text = listConfiguration.Name;

            //if (!string.IsNullOrEmpty(listConfiguration.Name))
            //{
            //    tbListName.Text = listConfiguration.Name;
            //    tbListName.Enabled = false;

            //    //switch (listConfiguration.ConfigType)
            //    //{
            //    //    case ListConfigurationType.Tree:
            //    //        {
            //    //            cbConfigurationType.SelectedItem = _treeConfigurationType;
            //    //            break;
            //    //        }
            //    //    case ListConfigurationType.HqlQuerry:
            //    //        {
            //    //            cbConfigurationType.SelectedItem = _hqlConfiguration;
            //    //            break;
            //    //        }
            //    //}

            //    //cbConfigurationType.Enabled = false;
            //}

            ShowVisible(true);
        }

        public override void SaveConfiguration(ListConfiguration listConfiguration)
        {
            listConfiguration.Name = tbListName.Text;
            listConfiguration.ConfigType = (cbConfigurationType.SelectedText == _treeConfigurationType) ? ListConfigurationType.Tree : ListConfigurationType.HqlQuerry; 
        }

        public override bool ValidateConfiguration()
        {
            if (tbListName.Text.Trim().Length == 0)
            {
                MessageBox.Show("Należy podać nazwę listy");
                return false;
            }

            return true;
        }
    }
}
